package com.car.advertising.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.car.advertising.R;
import com.car.advertising.connection.HttpUrl;
import com.car.advertising.view.EditTextDeleteView;
import com.support.widget.JumpManager;
import com.support.widget.layout.BaseToolBarActivity;
import com.support.widget.network.OkHttpClientManager;
import com.support.widget.util.ToastUtil;

import java.util.ArrayList;
import java.util.List;

public class CashAccountActivity extends BaseToolBarActivity {

    private TextView accountNumberTv;
    private EditTextDeleteView zhicubaoEdt;

    @Override
    protected void initToolBar() {
        setTitleClickable(false);
        setSubtitleClickable(true);
        setToolBarBackgroundColor(R.color.color_white);
        setToolBarTitle("提现账号");
        setToolBarTitleColor(R.color.black_bg);
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_cash_account);
        accountNumberTv = (TextView) findViewById(R.id.cash_account_number_tv);
        accountNumberTv.setOnClickListener(this);
        zhicubaoEdt = (EditTextDeleteView) findViewById(R.id.cash_zhifubao_edt);
    }

    @Override
    public String getCN() {
        return null;
    }

    @Override
    public void LogoutCallback(boolean islogin) {

    }

    @Override
    public void onCritClick(View v) {
        switch (v.getId()) {
            case R.id.cash_account_number_tv:
                String trim = zhicubaoEdt.getText().toString().trim();
                if (!TextUtils.isEmpty(trim)) {
                    updateCashAccount(trim);
                } else {
                    ToastUtil.show(CashAccountActivity.this, "请输入支付宝账号", Toast.LENGTH_SHORT);
                }
                break;
        }
    }


    private void updateCashAccount(String zhifubaoStr) {
        List<OkHttpClientManager.Param> params = new ArrayList<>();
        params.add(new OkHttpClientManager.Param("acToken", "T2_80_LqrB6XXYFDMbkqhX"));// 用户token
        // params.add(new OkHttpClientManager.Param("realName", "中国银行"));// 真实姓名，由实名制认证信息中获取
        params.add(new OkHttpClientManager.Param("zfbNo", zhifubaoStr));// 支付宝账号，支付宝与银行卡信息必填一个
//        params.add(new OkHttpClientManager.Param("bankCode", "1234"));// 银行编号
//        params.add(new OkHttpClientManager.Param("bankName", "1234"));// 银行名称
//        params.add(new OkHttpClientManager.Param("bankNo", "6225123123"));// 银行卡号
        OkHttpClientManager.postAsyn(HttpUrl.getInstance().URL_026, new OkHttpClientManager.ResultCallback<String>() {
            @Override
            public void onError(String request) {
                if (TextUtils.equals(request, "登录已过期")) {
                    JumpManager.gotoActivity(CashAccountActivity.this, LoginActivity.class, false);
                    finish();
                }
            }

            @Override
            public void onResponse(String resp) {
                ToastUtil.show(CashAccountActivity.this, "修改成功", Toast.LENGTH_SHORT);
                finish();
            }

            @Override
            public void onFinish() {
            }
        }, params, null);
    }

    @Override
    protected boolean isClickable() {
        return false;
    }

    @Override
    protected void subtitleClick() {

    }

    @Override
    protected void titleClick() {

    }

    @Override
    protected void rightClick() {

    }

}
